import axios from "axios";


const request = axios.create({
  baseURL: '',
});

// 添加请求拦截器
request.interceptors.request.use(config => {
  // 动态设置 Cookie
  config.headers.Cookie = '_ga=GA1.1.202771910.1738835572; UM_distinctid=196236a05cde0d-038023dd532446-1b525636-1fa400-196236a05ce35d0; _ga_89WN60ZK2E=GS2.1.s1747100229$o52$g0$t1747100229$j0$l0$h0; _yapi_uid=86; _yapi_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjg2LCJpYXQiOjE3NDc3MDg4MTEsImV4cCI6MTc0ODMxMzYxMX0.OsCY-GflGy_Crp2HoW_J-jKzUT25LfrVc8QABMtK3xU';
  return config;
}, error => {
  return Promise.reject(error);
});

request.interceptors.response.use(
  // 请求成功
  response => {
    let data = response.data;


    if (!(data instanceof Object)) {
      try {
        data = JSON.parse(data);
      } catch (error) {
        return Promise.reject(error);
      }
    }
    return data.data;
  },
  // 请求失败
  error => {
    return Promise.reject(error.response);
  },
);


export async function getYapiInterface(params) {
  return request.get(`https://yapi.zsdx.cn/api/interface/get?id=${params.id}`);
}

(async () => {
  const res = await getYapiInterface({ id: 17859 });

  console.log(res);
})();